| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var utilities = require('../src/utilities.js'); |
||
| 32 | describe('successful tests', function() { |
||
| 33 | // test example from README.md |
||
| 34 | var SuperClass = function() { |
||
| 35 | this.someProperty = 42; |
||
| 36 | }; |
||
| 37 | |||
| 38 | SuperClass.prototype.retMsg = function(msg) { |
||
| 39 | return msg; |
||
| 40 | }; |
||
| 41 | |||
| 42 | SuperClass.prototype.getSomeProp = function() { |
||
| 43 | return this.someProperty; |
||
| 44 | }; |
||
| 45 | |||
| 46 | // a class we want to inherit from SuperClass |
||
| 47 | var SomeClass = function() { |
||
| 48 | SuperClass.call(this); |
||
| 49 | }; |
||
| 50 | |||
| 51 | utilities.inherits(SomeClass, SuperClass); |
||
| 52 | |||
| 53 | SomeClass.prototype.flop = function(msg) { |
||
| 54 | return this.retMsg(msg); |
||
| 55 | }; |
||
| 56 | |||
| 57 | var someClass_instance = new SomeClass(); |
||
| 58 | // end test example from README.md |
||
| 59 | |||
| 60 | it('should be able to access inherited properties', function() { |
||
| 61 | expect(someClass_instance.someProperty).toEqual(42); |
||
| 62 | }); |
||
| 63 | |||
| 64 | it('should be able to run inherited methods', function() { |
||
| 65 | expect(someClass_instance.retMsg('hi')).toEqual('hi'); |
||
| 66 | }); |
||
| 67 | |||
| 68 | it('should be able to run inherited methods by using the this keyword', function() { |
||
| 69 | expect(someClass_instance.flop('hi')).toEqual('hi'); |
||
| 70 | }); |
||
| 71 | |||
| 72 | it('should be instance of SomeClass', function() { |
||
| 73 | expect(someClass_instance instanceof SomeClass).toEqual(true); |
||
| 74 | }); |
||
| 75 | |||
| 76 | it('should be instance of SuperClass', function() { |
||
| 77 | expect(someClass_instance instanceof SuperClass).toEqual(true); |
||
| 78 | }); |
||
| 79 | |||
| 80 | it('should set SuperClass contructor', function() { |
||
| 81 | expect(someClass_instance.constructor.super_ === SuperClass).toEqual( |
||
| 82 | true |
||
| 83 | ); |
||
| 84 | }); |
||
| 85 | |||
| 86 | it('should set contructor', function() { |
||
| 87 | expect(someClass_instance.constructor === SomeClass).toEqual(true); |
||
| 88 | }); |
||
| 89 | }); |
||
| 90 | }); |
||
| 91 |